package o;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.FrameLayout;

import androidx.core.view.ViewCompat;

import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.NetConfigAction;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.foundation.ui.framework.cardkit.widget.CardListAdapter;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView.a;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.gamebox.plugin.gameservice.view.TransferActivity;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;

import java.lang.ref.WeakReference;
import java.util.List;

import o.bkw.b;

public class BaseListSegment extends bgq implements a, chy, OnScrollListener, bhd, AccountBussinessListener, ciz {
    protected FrameLayout ʻ;
    protected long ʼ = -1;
    protected boolean ʽ = false;
    protected String ˊ;
    protected bfa ˊॱ;
    protected LoadingController mLoadCtrl;
    protected PullUpListView mListView;
    protected ViewGroup ˏ;
    protected CardListAdapter mCardListAdapter;
    protected String ͺ;
    protected boolean isLoadmoreEnbale = true;
    private boolean ॱˋ = false;
    private BroadcastReceiver mSafeReceiver = new SafeBroadcastReceiver(this) {
        final /* synthetic */ BaseListSegment mBaseFragment;

        {
            this.mBaseFragment = BaseListSegment.this;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if (context == null || intent == null) {
                Logger.e("BaseListSegment", "onReceive, context = " + context + ", intent = " + intent);
                return;
            }
            String action = intent.getAction();
            if (e.ॱ.equals(action)) {
                if (Logger.ˎ()) {
                    Logger.ˏ("BaseListSegment", "onReceive: REFRESH_ALL_CARD_ACTION");
                }
                this.mBaseFragment.ॱॱ.post(new c(this.mBaseFragment));
            } else if ("cardlist_show_toast_action".equals(action)) {
                action = intent.getStringExtra("toast_tips");
                if (!TextUtils.isEmpty(action) && this.mBaseFragment.ʾ() && this.mBaseFragment.ˈ()) {
                    ezn.ˊ().ˊ(action);
                } else {
                    Logger.e("BaseListSegment", "onReceive, tips: " + action + ", isInFront = " + this.mBaseFragment.ʾ() + ", isSelected = " + this.mBaseFragment.ˈ());
                }
            }
        }
    };
    protected Handler ॱॱ = new Handler();
    protected cia ᐝ;
    private bft ᐝॱ;

    public static class c implements Runnable {
        private WeakReference<BaseListSegment> ˎ;

        public c(BaseListSegment o_bgs) {
            this.ˎ = new WeakReference(o_bgs);
        }

        public void run() {
            BaseListSegment o_bgs = (BaseListSegment) this.ˎ.get();
            if (o_bgs == null) {
                Logger.e("BaseListSegment", "ReloadRunnable, listSegment == null");
            } else {
                o_bgs.ʽॱ();
            }
        }
    }

    protected void ͺ() {
        Bundle ˊˊ = ˊˊ();
        if (ˊˊ != null) {
            this.ˊ = ˊˊ.getString("SEGMENT_URI");
            this.ͺ = ˊˊ.getString("APPID");
            this.ʽ = ˊˊ.getBoolean("NEED_OBSERVE_ACC", false);
            this.ॱ = ˊˊ.getBoolean("IS_DATA_READY", false);
        } else {
            Logger.e("BaseListSegment", "parserArguments, arguments is null");
        }
        ˏॱ();
    }

    protected void ˏॱ() {
    }

    public void ॱ(Bundle bundle) {
        if (ˉ() == null) {
            Logger.e("BaseListSegment", "onCreate, context is null");
            return;
        }
        super.ॱ(bundle);
        this.ˋ = hashCode() + this.ˊ;
        ᐝॱ();
        Logger.ˎ("BaseListSegment", "OnCreate, segmentId: " + this.ˋ);
    }

    public View ˋॱ() {
        if (ˉ() == null) {
            Logger.e("BaseListSegment", "onCreateView, context is null");
            return null;
        }
        cgu.ˎ(ˉ());
        this.ˏ = (ViewGroup) LayoutInflater.from(ˉ()).inflate(ˏ(), null, false);
        ˋ(this.ˏ);
        Logger.ˎ("BaseListSegment", "onCreateView");
        if (this.mListView != null) {
            this.ᐝॱ = new bft(this.mListView);
        }
        return this.ˏ;
    }

    protected void ˋ(ViewGroup viewGroup) {
        this.mListView = (PullUpListView) viewGroup.findViewById(o.bgq.ResultCallback.ˏ);
        this.mListView.setNeedFootView(isNeedFooter());
        this.mListView.setVerticalScrollBarEnabled(false);
        this.mListView.setOnScrollListener(this);
        this.mListView.setDrawSelectorOnTop(false);
        this.mListView.setSelector(new ColorDrawable(0));
        this.mListView.setLoadingListener(this);
        this.mListView.setVisibility(8);
        this.ʻ = (FrameLayout) viewGroup.findViewById(o.bgq.ResultCallback.ॱॱ);
        this.mLoadCtrl = createLoadingController();
        viewGroup.addView(this.mLoadCtrl.ˏ(LayoutInflater.from(ˉ())));
        this.ᐝ = ˋ(ˉ().getApplicationContext());
        if (!this.ॱ) {
            this.mLoadCtrl.ˋ();
        } else if (this.ᐝ == null || this.ᐝ.ˊॱ() == 0) {
            ˏ(true);
            return;
        } else {
            ˊ(true);
            ॱ(0);
        }
        this.mCardListAdapter = ˏ(ˉ(), this.ᐝ);
        this.mCardListAdapter.setCardEventListener(this);
        this.mListView.setAdapter(this.mCardListAdapter);
    }

    protected cia ˋ(Context context) {
        return new cia(context);
    }

    public void onResume() {
        super.onResume();
        ʻ(true);
        if (this.ᐝ != null) {
            this.ᐝ.ͺ();
            Logger.ˎ("BaseListSegment", "onResume");
        } else if (Logger.ˎ()) {
            Logger.ˏ("BaseListSegment", "provider is null");
        }
    }

    public void onStop() {
        super.onStop();
        ʻ(false);
        Logger.ˎ("BaseListSegment", "onStop");
    }

    public void ˊ(bfa o_bfa) {
        this.ˊॱ = o_bfa;
    }

    protected void refreshTitle(String str) {
        if (Logger.ˎ()) {
            Logger.ˏ("BaseListSegment", "refreshTitle");
        }
        if (this.ˊॱ != null) {
            this.ˊॱ.ˏ(str);
        }
    }

    public void onDestroy() {
        ॱˎ();
        if (this.mCardListAdapter != null) {
            this.mCardListAdapter.destroy();
            this.mCardListAdapter = null;
        }
        super.onDestroy();
        Logger.ˎ("BaseListSegment", "onDestroy, segmentId: " + this.ˋ);
    }

    protected CardListAdapter ˏ(Context context, cia o_cia) {
        return new CardListAdapter(context, o_cia);
    }

    protected LoadingController createLoadingController() {
        LoadingController mCtroller = new LoadingController();
        mCtroller.ˏ((bhd) this);
        mCtroller.ˎ(new OnClickListener(this) {
            final /* synthetic */ BaseListSegment ˋ;

            {
                this.ˋ = r1;
            }

            public void onClick(View view) {
                Logger.ˎ("BaseListSegment", "createLoadingController onClick, onLoadingRetry");
                this.ˋ.ʼᐝ();
            }
        });
        return mCtroller;
    }

    public void ʽᐝ() {
        ˋ();
        Logger.ˎ("BaseListSegment", "OnLoadingMore, maxId: " + this.ʼ + ", detailUri: " + this.ˊ);
    }

    public void ʼᐝ() {
        this.mListView.ʻ();
        ˋ();
        Logger.ˎ("BaseListSegment", "onLoadingRetry, maxId: " + this.ʼ + ", detailUri: " + this.ˊ);
    }

    public void ˈॱ() {
    }

    public void ˊʼ() {
    }

    public void ʿॱ() {
    }

    protected int ˏ() {
        return b.ˎ;
    }

    protected void ᐝॱ() {
        if (this.ʽ) {
            eoj.ˋ().ˎ(this.ˋ, this);
        }
        ॱᐝ();
    }

    protected void ॱˎ() {
        if (this.ʽ) {
            eoj.ˋ().ˊ(this.ˋ);
        }
        ʻॱ();
    }

    protected void ॱᐝ() {
        IntentFilter intentFilter = new IntentFilter(e.ॱ);
        intentFilter.addAction("cardlist_show_toast_action");
        ll.ˏ(ContentManager.getInstant().getContext()).ˏ(this.mSafeReceiver, intentFilter);
    }

    protected void ʻॱ() {
        ll.ˏ(ContentManager.getInstant().getContext()).ˋ(this.mSafeReceiver);
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        if (o_ccp == null) {
            Logger.e("BaseListSegment", "onAccountBusinessResult, accountResult == null");
        } else if (102 == o_ccp.ˎ || 103 == o_ccp.ˎ) {
            Logger.ˎ("BaseListSegment", "onAccountBusinessResult, login status: " + o_ccp);
            this.ॱॱ.post(new c(this));
        }
    }

    public void onScrollStateChanged(AbsListView absListView, int i) {
        if (i != 2) {
            ॱ(i);
        }
    }

    public void onScroll(AbsListView absListView, int i, int i2, int i3) {
    }

    public void ʼॱ() {
        if (ˉ() == null) {
            Logger.e("BaseListSegment", "onSetting, context is null");
            return;
        }
        Intent intent = new Intent(ˉ(), TransferActivity.class);
        intent.setAction(NetConfigAction.ACTION_NET_CONFIG);
        ((faj) cdb.ॱ(faj.class)).ˎ(this.ॱᐝ, TransferActivity.class, intent, true);
    }

    public void ˏ(int i, cih o_cih) {
        if (i == 0 || 9 == i) {
            BaseCardBean baseCardBean = (BaseCardBean) o_cih.ˌ();
            if (baseCardBean == null || baseCardBean.ॱॱ() == null || ˉ() == null) {
                Logger.ˎ("BaseListSegment", "onClick, cardBean: " + baseCardBean + ", context: " + ˉ());
            } else if (!cii.ˊ().ˊ(ˉ(), baseCardBean, i, String.valueOf(4))) {
                ezn.ˊ().ˊ(ˉ().getResources().getString(bkw.e.ॱ));
                Logger.e("BaseListSegment", "onClick, dispatch failed, uri = " + baseCardBean.ॱॱ());
            }
        }
    }

    public List<CardBean> ˎ(String str, String str2) {
        return null;
    }

    public boolean ad_() {
        if (this.mListView == null || ViewCompat.ˏ(this.mListView, -1)) {
            return false;
        }
        return true;
    }

    protected void ʽॱ() {
        if (this.ᐝ != null) {
            this.ᐝ.ॱॱ();
        }
        ˎ(false);
        this.ʼ = -1;
        ˏ(false);
        ˋ();
    }

    protected void ˏ(boolean z) {
        if (this.ʻ != null) {
            this.ʻ.setVisibility(z ? 0 : 4);
        } else {
            Logger.e("BaseListSegment", "setNoDataViewVisible, noDataView is null");
        }
    }

    protected void ˊ(boolean z) {
        if (this.mListView == null) {
            Logger.e("BaseListSegment", "setListViewVisiable, listView is null");
        } else if (z) {
            this.mListView.setVisibility(0);
            this.ॱˋ = true;
        } else {
            this.mListView.setVisibility(8);
            this.ॱˋ = false;
        }
    }

    public boolean isNeedFooter() {
        return this.isLoadmoreEnbale;
    }

    public void ॱ(boolean z) {
        this.isLoadmoreEnbale = z;
    }

    public boolean ॱ(bgq o_bgq, bgq.e eVar) {
        BaseRequest o_cvu = eVar.mReq;
        ResponseBean responseBean = eVar.mResp;
        if (responseBean.getResponseType() != ResponseBean.a.FROM_CACHE) {
            ˎ(null);
        }
        if (Logger.ˎ()) {
            Logger.ˏ("BaseListSegment", "onCompleted, " + ", method: " + o_cvu.getMethod_() + ", responseCode: " + responseBean.getResponseCode() + ", rtnCode: " + responseBean.getRtnCode_() + ", responseType: " + responseBean.getResponseType());
        }
        if (ˋ(responseBean)) {
            ˏ(o_cvu, responseBean);
        } else {
            ˊ(responseBean);
        }
        return false;
    }

    protected boolean ˋ(ResponseBean responseBean) {
        if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
            return true;
        }
        Logger.e("BaseListSegment", "isSuccess false, rtnCode: " + responseBean.getRtnCode_() + ", responseCode: " + responseBean.getResponseCode());
        return false;
    }

    protected void ˊ(BaseRequest o_cvu, ResponseBean responseBean) {
    }

    protected void ˏ(BaseRequest o_cvu, ResponseBean responseBean) {
    }

    protected void ˋ(boolean z) {
        if (this.ᐝ != null) {
            this.ᐝ.ˏ(z);
        }
    }

    protected void ˊ(ResponseBean responseBean) {
        if (responseBean.getResponseType() != ResponseBean.a.UPDATE_CACHE) {
            if (this.mLoadCtrl != null) {
                this.mLoadCtrl.ॱ(responseBean.getResponseCode(), responseBean.getRtnCode_());
            }
            if (this.mListView != null) {
                this.mListView.ॱˊ();
            }
        }
    }

    public String toString() {
        return "detailUri:" + this.ˊ;
    }

    private bft ˊᐝ() {
        if (this.ᐝॱ == null) {
            this.ᐝॱ = new bft(this.mListView);
        }
        return this.ᐝॱ;
    }

    protected void ॱ(int i) {
        if (!(this.mListView == null && this.ᐝॱ == null) && i == 0 && this.ॱˋ) {
            ˊᐝ().ˎ();
        }
    }
}
